<template>
  <div class="menu-bar">
    <!-- 最底侧菜单条 -->
    <transition name="slide-up">
      <div
        class="menu-wrapper"
        v-show="isTitleAndMenuShow"
        :class="{'hide-box-shadow':isSettingShow || !isTitleAndMenuShow}"
      >
        <div
          class="icon-wrapper"
          @click="showSetting(3)"
        >
          <span class="iconfont iconmenu"></span>
        </div>
        <div
          class="icon-wrapper"
          @click="showSetting(2)"
        >
          <span class="iconfont iconprogress"></span>
        </div>
        <div
          class="icon-wrapper"
          @click="showSetting(1)"
        >
          <span class="iconfont iconliangdu-"></span>
        </div>
        <div
          class="icon-wrapper"
          @click="showSetting(0)"
        >
          <span class="iconfont iconfont-font"></span>
        </div>
      </div>
    </transition>
    <!-- 倒数第二底侧菜单条 -->
    <transition name="slide-up">
      <div
        class="setting-wrapper"
        v-show="isSettingShow"
      >
        <!-- 设置字号大小 -->
        <div
          class="setting-font-size"
          v-if="showTag === 0"
        >
          <div
            class="preview"
            :style="{ fontSize : fontSizeList[0].fontSize+'px'}"
          >A</div>
          <div class="select">
            <div
              class="select-wrapper"
              v-for="(item, index) in fontSizeList"
              :key="index"
              @click="setFontSize(item.fontSize)"
            >
              <div class="line"></div>
              <div class="point-wrapper">
                <div
                  class="point"
                  v-show="defaultFontSize === item.fontSize"
                >
                  <div class="small-point"></div>
                </div>
              </div>
              <div class="line"></div>
            </div>
          </div>
          <div
            class="preview"
            :style="{ fontSize : fontSizeList[fontSizeList.length-1].fontSize+'px'}"
          >A</div>
        </div>
        <!-- 设置主题 -->
        <div
          class="setting-theme"
          v-else-if="showTag === 1"
        >
          <div
            class="setting-theme-item"
            v-for="(item, index) in themesList"
            :key="index"
            @click="setTheme(index)"
          >
            <div
              class="preview"
              :style="{background: item.style.body.background}"
              :class="{'no-border':item.style.body.background !== '#fff'}"
            ></div>
            <div
              class="text"
              :class="{'seleted':index===defaultTheme}"
            >{{item.name}}</div>
          </div>
        </div>
        <!-- 设置进度条 -->
        <div
          class="setting-progress"
          v-else-if="showTag === 2"
        >
          <input
            class="progress"
            type="range"
            max="100"
            min="0"
            step="1"
            @change="onProgressChange($event.target.value)"
            @input="onProgressChange($event.target.value)"
            :value="progress"
            :disabled="!bookAvailable"
            ref="progress"
          >
          <div class="text-wrapper">
            <span>{{bookAvailable ? progress + '%':'加载中...'}}</span>
          </div>
        </div>
      </div>
    </transition>
    <!-- 目录 -->
    <ContentView
      :isShowContent="isShowContent"
      :navigation="navigation"
      :bookAvailable="bookAvailable"
      @jumpTo="jumpTo"
    ></ContentView>
    <transition name="fade">
      <div
        class="content-mask"
        v-show="isShowContent"
        @click="hideContent"
      ></div>
    </transition>
  </div>
</template>

<script>
import ContentView from './ContentView'
export default {
  components: { ContentView },
  props: {
    isTitleAndMenuShow: {
      type: Boolean,
      default: false
    },
    fontSizeList: Array,
    defaultFontSize: Number,
    defaultTheme: Number,
    themesList: Array,
    // 图书是否加载完毕
    bookAvailable: Boolean,
    navigation: Object
  },
  data () {
    return {
      isSettingShow: false,
      showTag: 0,
      progress: 0,
      isShowContent: false
    }
  },
  methods: {
    jumpTo (href) {
      this.$emit('jumpTo', href)
    },
    hideContent () {
      this.isShowContent = false
    },
    // 调节进度条
    onProgressChange (progress) {
      this.$emit('onProgressChange', progress)
      this.onProgressInput(progress)
    },
    onProgressInput (progress) {
      this.progress = progress
      this.$refs.progress.style.backgroundSize = `${this.progress}% 100%`
    },
    setTheme (index) {
      this.$emit('setTheme', index)
    },
    showSetting (index) {
      this.showTag = index
      if (this.showTag === 3) {
        this.isShowContent = true
        this.isSettingShow = false
      } else {
        this.isSettingShow = true
      }
    },
    hideSetting () {
      this.isSettingShow = false
    },
    setFontSize (fontSize) {
      this.$emit('setFontSize', fontSize)
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/assets/styles/global.scss';
.menu-bar {
  .menu-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 101;
    width: 100%;
    height: px2rem(48);
    background: #c7c7c7;
    box-shadow: 0 - px2rem(8) px2rem(8) rgba($color: #000, $alpha: 0.15);
    display: flex;
    .icon-wrapper {
      flex: 1;
      @include center;
      .iconprogress {
        font-size: px2rem(26);
      }
      .iconliangdu- {
        font-size: px2rem(24);
      }
    }
  }
  .setting-wrapper {
    position: absolute;
    left: 0;
    z-index: 100;
    bottom: px2rem(48);
    height: px2rem(60);
    width: 100%;
    box-shadow: 0 px2rem(-8) px2rem(8) rgba($color: #000000, $alpha: 0.15);
    background: #c7c7c7;
    .setting-font-size {
      display: flex;
      height: 100%;
      .preview {
        flex: 0 0 px2rem(40);
        @include center;
      }
      .select {
        display: flex;
        flex: 1;
        .select-wrapper {
          flex: 1;
          display: flex;
          align-items: center;
          &:first-child {
            .line {
              &:first-child {
                border-top: none;
              }
            }
          }
          &:last-child {
            .line {
              &:last-child {
                border-top: none;
              }
            }
          }
          .line {
            flex: 1;
            height: 0;
            border-top: px2rem(1) solid #a3a3a5;
          }
          .point-wrapper {
            position: relative;
            flex: 0 0 0;
            width: 0;
            height: px2rem(7);
            border-left: px2rem(1) solid #a3a3a5;
            .point {
              position: absolute;
              top: 50%;
              left: 50%;
              width: px2rem(20);
              height: px2rem(20);
              transform: translate(-50%, -50%);
              border-radius: 50%;
              background: #c7c7c7;
              box-shadow: px2rem(1) px2rem(4) px2rem(4)
                rgba($color: #000000, $alpha: 0.1);
              @include center;
              .small-point {
                background: #000;
                width: px2rem(5);
                height: px2rem(5);
                border-radius: 50%;
              }
            }
          }
        }
      }
    }
    .setting-theme {
      width: 100%;
      display: flex;
      height: 100%;
      .setting-theme-item {
        padding: px2rem(5);
        box-sizing: border-box;
        flex: 1;
        display: flex;
        flex-direction: column;
        background: #c7c7c7;
        .preview {
          flex: 1;
          border: px2rem(1) solid #ccc;
          box-sizing: border-boxƒ;
          &.no-border {
            border: none;
          }
        }
        .text {
          flex: 0 0 px2rem(20);
          font-size: px2rem(14);
          @include center;
          color: #999;
          &.seleted {
            color: #333;
          }
        }
      }
    }
    .setting-progress {
      height: 100%;
      width: 100%;
      @include center;
      flex-direction: column;
      padding: 0 px2rem(30);
      box-sizing: border-box;
      .progress {
        width: 100%;
        // 清除默认样式
        -webkit-appearance: none;
        height: px2rem(2);
        background: -webkit-linear-gradient(#53575d, #53575d) no-repeat, #abacae;
        background-size: 0 100%;
        &:focus {
          outline: none;
        }
        &::-webkit-slider-thumb {
          -webkit-appearance: none;
          height: px2rem(15);
          width: px2rem(15);
          border-radius: 50%;
          background: #fff;
          box-shadow: 0 4px 4px 0 rgba($color: #000000, $alpha: 0.15);
          border: px2rem(1) solid #ddd;
        }
      }
      .text-wrapper {
        display: flex;
        // align-items: center;
        justify-content: center;
        width: 100%;
        height: px2rem(16);
        span {
          margin-top: 25px;
          @include center;
          width: 100%;
          font-size: px2rem(16);
        }
      }
    }
  }
  .content-mask {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 101;
    display: flex;
    width: 100%;
    height: 100%;
    background: rgba(51, 51, 51, 0.8);
  }
  .hide-box-shadow {
    box-shadow: 0 0 0;
  }
}
</style>
